* This is to reproduce the regressions in the study
* "Majoritarian democracy udermines truth-finding in deliberative committees"
* Jan Lorenz, Heiko Rauhut, Bernhard Kittel
* The main analysis and data handling is made in r in 
* LorenzRauhutKittel_DataFigures.r

********************************** 
**		Header 
********************************** 
{  
clear 
version 12      
capture log close
set more off 
global datapath /* write here your data path, e.g. C:\prof\data  */
global figurepath /* write here your figure path, e.g. C:\prof\figs  */
global logpath /* write here your log path, e.g. C:\prof\log  */

capture log close
capture log using "$logpath\treatment_woc.log", replace
set scheme s1manual

capture program drop savefig
	program savefig
		foreach f in pdf eps png{
		graph export $figurepath\\`1'.`f', replace
		}
	end	
}

********************************** 
* data set
********************************** 

use "groups.dta", clear
tab questionid, gen(q_id)
tab institution, gen(inst)

********************************** 
* Table 2, main paper: 
* Mixed effects regression with agreement rule 
* as fixed effects and 
* questions as random effects:
********************************** 

mixed changeperformance inst1 inst3 || questionid:

* Hausman test: Paper in Sec. 4 Results
hausman fe .

********************************** 
* Table 5, Online Appendix: 
* Full factorial model of all treatment effects 
* and their interactions on change in performance:
********************************** 

gen groupsize = 0 if numingroup == 3
replace groupsize = 1 if numingroup == 9
sum groupsize
tab groupsize numingroup

gen i1_gs = inst1 * groupsize
gen i2_gs = inst2 * groupsize
gen i3_gs = inst3 * groupsize
gen i1_chat = inst1 * chat
gen i2_chat = inst2 * chat
gen i3_chat = inst3 * chat
gen gs_chat = groupsize * chat

* regression models
reg changeperformance inst1 inst3 groupsize chat 
eststo changemain
reg changeperformance inst1 inst3 groupsize chat i1_gs i3_gs i1_chat i3_chat gs_chat
eststo changeinter

* compile formatted table with two models
#d;
esttab changemain changeinter
	using $figurepath\performance.tex, replace
	mtitles("change in performance" "change in performance")
	coeflabels(
		inst1 "individual"
		inst2 "majority"
		inst3 "unanimity"
		groupsize "group size"
		i1_gs "individual $\times$ group size"
		i2_gs "majority $\times$ group size"
		i3_gs "unanimity $\times$ group size"
		i1_chat "individual $\times$ chat"
		i2_chat "majority $\times$ chat"
		i3_chat "unanimity $\times$ chat"
		gs_chat "group size $\times$ chat"
		_cons "intercept"
		)
		star(* 0.10 ** 0.05 *** 0.01)
		p
		;
#d cr

********************************** 
* Tab. 6, model (1), Online Appendix: 
* Robustness analysis of 
* the effect of different agreement rules 
* on performance for different knowledge
* questions 
********************************** 

mixed changeperformance inst1 inst3 q_id2-q_id19
estimates store fe

* Tab. 6, model (2), Online Appendix 
drop q_id*
keep if questionid == "2" | questionid == "4" | questionid == "6" | questionid == "8"
tab questionid, gen(q_id)
mixed changeperformance inst1 inst3 q_id2-q_id4


********************************** 
* Chat analysis, 
* Table 7, Online Appendix
*
* data available on request
*
* Linear regression models of the 
* number of chats per individual (models 1--2) and 
* the chat time in seconds per subject (models 3--4)
********************************** 

*	individual time until ready
global condition = "individual majority unanimity if chat==1, noconstant cluster(runid)"
reg seconddecisionready $condition
eststo tmean

global condition = "individual majority if chat==1, cluster(runid)"
reg seconddecisionready $condition
eststo treatdiffmean

*	number of chats
reg numchatmessages individual majority unanimity if chat==1, noconstant cluster(runid)
eststo m1

reg numchatmessages individual majority if chat==1
eststo m2

*	compile table
#d;
esttab m1 m2 tmean treatdiffmean  
	using $figurepath\chat_final_subjectdata.tex, replace
	mtitles("chats" "chats" "time" "time" )
	coeflabels(institution "treatment" _cons "intercept")
	;
#d cr

log close
